#include "vcl_stl.h"

#include "bkbase.h"
#include "h_base.h"
#include "h_xml.h"
#include "simbat.h"
using namespace h_base;
using namespace simbat;

enum HBatchStatus
{
   bsBEGIN,
   bsNotStarted = bsBEGIN,
   bsStarted,
   bsPaused,
   bsStopping,
   bsStopped,
   bsEND = bsStopped
};

struct HBatch
{
   HBatchStatus Status;
   char StartTime[8 + 6 + 1];
   char EndTime[8 + 6 + 1];
   char Name[80 + 1];
   char Filler[120];
};

enum HJobStatus
{
   jsBEGIN,
   jsWaiting = jsBEGIN,
   jsRunning,
   jsSkipped,
   jsFail,
   jsSuccess,
   jsUnknown,
   jsEND = jsUnknown
};

struct HJobEvent
{
   char JobName[80 + 1];
   char PartId[80 + 1];
   char Time[8 + 6 + 1];
   char Filler[7];
   int NumOfPart;
   pid_t Pid;
   HJobStatus Status;
   char EyeCatcher[6];
};

int main()
{
   FILE *fin = fopen("a.dat", "rb");
   FILE *fout = fopen("b.dat", "wb");

/*
   HBatch Batch;

   fread(&Batch, sizeof(Batch), 1, fin);
   Batch.Status = (HBatchStatus)BkSwapLong((int)Batch.Status);
   fwrite(&Batch, sizeof(Batch), 1, fout);
*/
   for ( ; ; )
   {
      HJobEvent Event;
      if ( fread(&Event, sizeof(Event), 1, fin) != 1 )
      {
         break;
      }
      Event.NumOfPart = (int)BkSwapLong((int)Event.NumOfPart);
      Event.Pid = (int)BkSwapLong((int)Event.Pid);
      Event.Status = (HJobStatus)BkSwapLong((int)Event.Status);
      fwrite(&Event, sizeof(Event), 1, fout);
   }

   fclose(fout);
   fclose(fin);
   return 0;
}
